﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Text.RegularExpressions;

namespace BLL.Concrete.Validations
{
    public class RegisterData : IDataErrorInfo
    {
        public const string MatchEmailPattern =
            @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
     + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
				[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
     + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
				[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
     + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";
        public String Email { get; set; }
        public String Password { get; set; }
        public String Nombre { get; set; }
        public String Apellido { get; set; }
        public String Cedula { get; set; }
        public String Telefono { get; set; }
        public int Encuesta { get; set; }

        #region IDataErrorInfo Members
        public String Error { get; set; }

        public string this[string columnName]
        {
            get
            {
                if ((columnName == "Email") && String.IsNullOrEmpty(Email))
                {
                    Error = "Email invalido";
                    return "*";
                }
                else if ((columnName == "Email") && !Regex.IsMatch(Email, MatchEmailPattern))
                {
                    // regex
                    Error = "Email invalido";
                    return "*";
                }
                if ((columnName == "Password") && String.IsNullOrEmpty(Password))
                {
                    Error = "Contraseña invalida";
                    return "*";
                }
                if ((columnName == "Nombre") && String.IsNullOrEmpty(Nombre))
                {
                    Error = "Nombre invalido";
                    return "*";
                }
                if ((columnName == "Cedula") && String.IsNullOrEmpty(Cedula))
                {
                    Error = "Cedula invalida";
                    return "*";
                }
                if ((columnName == "Telefono") && String.IsNullOrEmpty(Telefono))
                {
                    Error = "Telefono invalido";
                    return "*";
                }
                return null;
            }
        }

        #endregion
    }
}
